﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using BussinesLogic;
using System.Collections;

namespace DataAccess.Factory
{
    class FolioFactoryDao : BaseFactory
    {

        public FolioFactoryDao()
        {
            this.classType = typeof(Folio);
        }

        private string uspGetFolio = @"fd_Folio_get_Folio";
        private string uspGetFoliosByDocument = @"fd_Folio_gets_by_document";
        private string uspGetFolioById = @"fd_Folio_get_by_id";

        /* funciones */

        public Folio getFolioById(int id)
        {
            SqlParameter[] parameter = new SqlParameter[1];

            parameter[0] = new SqlParameter("@id", id);

            ArrayList obj = this.DataTableToObjectList(parameter, this.uspGetFolioById);

            if (obj != null && obj.Count > 0)
            {
                return (Folio)obj[0];
            }
            else
            {
                return null;
            }

        }

        public ArrayList getFoliosByDocument(string codeDoc)
        {
            SqlParameter[] parameter = new SqlParameter[1];

            parameter[0] = new SqlParameter("@codeDoc", codeDoc);

            ArrayList obj = this.DataTableToObjectList(parameter, this.uspGetFoliosByDocument);

            if (obj != null && obj.Count > 0)
            {
                return obj;
            }
            else
            {
                return null;
            }

        }

        public Folio getFolio(int NumFolio, string CodDocumento, string NoExpediente)
        {
            SqlParameter [] parameter = new SqlParameter[3];

            parameter[0] = new SqlParameter("@NumFolio", NumFolio);
            parameter[1] = new SqlParameter("@CodDocumento", CodDocumento);
            parameter[2] = new SqlParameter("@NoExpediente", NoExpediente);

            ArrayList obj = this.DataTableToObjectList(parameter, this.uspGetFolio);

            if (obj != null && obj.Count > 0)
            {
                return (Folio)obj[0];
            }
            else
            {
                return null;
            }
            
        }
    }
}
